package com.zimmur.controller;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.zimmur.common.ReturnJsonEntity;
import com.zimmur.common.StatusCodeEnum;
import com.zimmur.service.ISolrService;

@RestController
@RequestMapping("/api/solr")
public class SolrApiController extends BaseController {

	@Resource
	private ISolrService solrService;
	
	@ResponseBody
	@RequestMapping(value="/addOrUpdateGoods")  
	public ReturnJsonEntity saveOrUpdateGoods(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		String goodsId=getParam("goodsId");
		
		int flag=solrService.addGoods(goodsId);
		StatusCodeEnum code=StatusCodeEnum.APICODE100000;
		if(flag==0){
			code=StatusCodeEnum.APICODE000000;
		}else if(flag==1){
			code=StatusCodeEnum.APICODE100401;
		}
		entity.setCode(code.getCode());
		entity.setMsg(code.getMsg());
		return entity;
	}
	@ResponseBody
	@RequestMapping(value="/deleteGoods")  
	public ReturnJsonEntity deleteGoods(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		String goodsIds=getParam("goodsIds");
		int flag=solrService.deleteGoods(goodsIds);
		StatusCodeEnum code=StatusCodeEnum.APICODE100000;
		if(flag==0){
			code=StatusCodeEnum.APICODE000000;
		}else if(flag==1){
			code=StatusCodeEnum.APICODE100401;
		}
		entity.setCode(code.getCode());
		entity.setMsg(code.getMsg());
		return entity;
	}
	@ResponseBody
	@RequestMapping(value="/saveOrUpdateDesigner")  
	public ReturnJsonEntity saveOrUpdateDesigner(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		String userId=getParam("userId");
		int flag=solrService.addDesigner(userId);
		StatusCodeEnum code=StatusCodeEnum.APICODE100000;
		if(flag==0){
			code=StatusCodeEnum.APICODE000000;
		}else if(flag==1){
			code=StatusCodeEnum.APICODE100401;
		}
		entity.setCode(code.getCode());
		entity.setMsg(code.getMsg());
		return entity;
	}
	@ResponseBody
	@RequestMapping(value="/deleteDesigner")  
	public ReturnJsonEntity deleteDesigner(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		String userIds=getParam("userIds");
		int flag=solrService.deleteDesigner(userIds);
		StatusCodeEnum code=StatusCodeEnum.APICODE100000;
		if(flag==0){
			code=StatusCodeEnum.APICODE000000;
		}else if(flag==1){
			code=StatusCodeEnum.APICODE100401;
		}
		entity.setCode(code.getCode());
		entity.setMsg(code.getMsg());
		return entity;
	}
	@ResponseBody
	@RequestMapping(value="/saveOrUpdateTopic")  
	public ReturnJsonEntity saveOrUpdateTopic(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		String topicId=getParam("topicId");
		int flag=solrService.addTopic(topicId);
		StatusCodeEnum code=StatusCodeEnum.APICODE100000;
		if(flag==0){
			code=StatusCodeEnum.APICODE000000;
		}else if(flag==1){
			code=StatusCodeEnum.APICODE100401;
		}
		entity.setCode(code.getCode());
		entity.setMsg(code.getMsg());
		return entity;
	}
	@ResponseBody
	@RequestMapping(value="/deleteTopic")  
	public ReturnJsonEntity deleteTopic(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		String topicIds=getParam("topicIds");
		int flag=solrService.deleteTopic(topicIds);
		StatusCodeEnum code=StatusCodeEnum.APICODE100000;
		if(flag==0){
			code=StatusCodeEnum.APICODE000000;
		}else if(flag==1){
			code=StatusCodeEnum.APICODE100401;
		}
		entity.setCode(code.getCode());
		entity.setMsg(code.getMsg());
		return entity;
	}
	
}
